//author:jxx
//此处是对表单的方法，组件，权限操作按钮等进行任意扩展(方法扩展可参照SellOrder.js)
let extension = {
    components: {//动态扩充组件或组件路径
        //表单header、content、footer对应位置扩充的组件
        gridHeader: '',//{ template: "<div>扩展组xx件</div>" },
        gridBody: '',
        gridFooter: '',
        //弹出框(修改、编辑、查看)header、content、footer对应位置扩充的组件
        modelHeader: '',
        modelBody: '',
        modelFooter: ''
    },
    buttons: { view: [], box: [], detail: [] },//扩展的按钮
    methods: {//事件扩展
        getFormOption (field) {
            let option;
            this.editFormOptions.forEach((x) => {
                x.forEach((item) => {
                    if (item.field == field) {
                        option = item;
                    }
                });
            });
            return option;
        },
        getSearchFormOptions (field) {
            let option;
            this.searchFormOptions.forEach((x) => {
                x.forEach((item) => {
                    if (item.field == field) {
                        option = item;
                    }
                });
            });
            return option;
        },
        onInit () {
            this.boxOptions.width = 600
            this.boxOptions.height = 400;
            let campsiteId = this.getFormOption('campsiteId')
            let campsitePhaseId = this.getFormOption('campsitePhaseId')
            campsiteId.onChange = (n) => {
                let parmas = {
                    order: "desc",
                    page: 1,
                    rows: 100,
                    sort: "phase_id_fk",
                    wheres: `[{"name":"campsite_id_fk","value":"${n}","displayType":"text"}]`,
                };
                this.http.post("/api/V_campphase/getPageData", parmas).then((res) => {
                    campsitePhaseId.data = res.rows.map((i) => {
                        return {
                            key: i.phase_id_fk,
                            value: i.phase_name,
                        };
                    });
                });
            }
            let parmas2 = {
                order: "desc",
                page: 1,
                rows: 100,
                sort: "phase_id_fk",
                wheres: `[]`,
            };
            let list = []
            this.http.post("/api/V_campphase/getPageData", parmas2).then((res) => {
                list = res.rows.map((i) => {
                    return {
                        key: i.phase_id_fk,
                        value: i.phase_name,
                    };
                });
                this.columns.forEach(i => {
                    if (i.field == 'campsitePhaseId') {
                        i.bind.data = list
                    }
                })
            });
            let campsiteId2 = this.getSearchFormOptions('campsiteId')
            let campsitePhaseId2 = this.getSearchFormOptions('campsitePhaseId')
            campsiteId2.onChange = (n) => {
                let parmas = {
                    order: "desc",
                    page: 1,
                    rows: 100,
                    sort: "phase_id_fk",
                    wheres: `[{"name":"campsite_id_fk","value":"${n}","displayType":"text"}]`,
                };
                this.http.post("/api/V_campphase/getPageData", parmas).then((res) => {
                    campsitePhaseId2.data = res.rows.map((i) => {
                        return {
                            key: i.phase_id_fk,
                            value: i.phase_name,
                        };
                    });
                });
            }
        },
        rowClick ({ row, column, event }) {
            this.$refs.table.$refs.table.toggleRowSelection(row);
            return true;
        },
        modelOpenBefore (row) {  //点击编辑/新建按钮弹出框后，可以在此处写逻辑，如，从后台获取数据
            if (this.currentAction == 'Add') {

            } else {
                let campsitePhaseId = this.getFormOption('campsitePhaseId')
                let parmas = {
                    order: "desc",
                    page: 1,
                    rows: 100,
                    sort: "phase_id_fk",
                    wheres: `[{"name":"campsite_id_fk","value":"${row.campsiteId}","displayType":"text"}]`,
                };
                this.http.post("/api/V_campphase/getPageData", parmas).then((res) => {
                    campsitePhaseId.data = res.rows.map((i) => {
                        return {
                            key: i.phase_id_fk.toString(),
                            value: i.phase_name,
                        };
                    });
                });
            }
        },
    }
};
export default extension;